#ifndef _IOAPIC_H
#define _IOAPIC_H

#include <type.h>

#define IOAPIC_IOREGSEL             0x00
#define IOAPIC_IOWIN                0x10
#define IOAPIC_IOREDTBL_BASE        0x10

#define IOAPIC_REG_ID               0x00
#define IOAPIC_REG_VER              0x01
#define IOAPIC_REG_ARB              0x02

#define IOAPIC_DELMOD_FIXED         0b000
#define IOAPIC_DELMOD_LPRIO         0b001
#define IOAPIC_DELMOD_NMI           0b100

#define IOAPIC_MASKED               (1 << 16)
#define IOAPIC_TRIG_LEVEL           (1 << 15)
#define IOAPIC_INTPOL_L             (1 << 13)
#define IOAPIC_DESTMOD_LOGIC        (1 << 11)

void ioapic_init();

void ioapic_write(u8 sel, u32 val);

u32 ioapic_read(u8 sel);

void ioapic_redirect(u8 irq, u8 vector, u8 dst_cpu, u32 flags);

u8 ioapic_get_irq(u8 old_irq);

#endif /* _IOAPIC_H */